#ifndef _STATE_TASK_H_
#define _STATE_TASK_H_

#include "stdint.h"


/*矩阵键盘发送数据*/
//#define KEY0 0xff //I/O扩展板输出引脚电平，当无按键按下时，全部引脚处于高电平状态，按下则对应行列引脚电平拉低则可读取
//#define KEY1 0xee
//#define KEY2 0xed
//#define KEY3 0xec
//#define KEY4 0xeb
//#define KEY5 0xde
//#define KEY6 0xdd
//#define KEY7 0xdc
//#define KEY8 0xdb
//#define KEY9 0xbe
//#define KEY10 0xbd
//#define KEY11 0xbc
//#define KEY12 0xbb
//#define KEY13 0x7e
//#define KEY14 0x7d
//#define KEY15 0x7c
//#define KEY16 0x7b



#define KEY0_0 0xEE
#define KEY0_1 0xDE
#define KEY0_2 0xBE
#define KEY0_3 0x7E

#define KEY1_0 0xED
#define KEY1_1 0xDD
#define KEY1_2 0xBD
#define KEY1_3 0x7D

#define KEY2_0 0xEB
#define KEY2_1 0xDB
#define KEY2_2 0xBB
#define KEY2_3 0x7B

#define KEY3_0 0xE7
#define KEY3_1 0xD7
#define KEY3_2 0xB7
#define KEY3_3 0x77


#define PCF8574_WRITE_ADDRESS 0x40
#define PCF8574_READ_ADDRESS 0x41
/*---------------------------------------------------------------------------monitor task-----------------------------------------------------------------------------------*/
/**
 * @brief 任务监视器结构体，能读取每个任务的计数器，任务周期及根据条件判断任务是否卡死给出标志位
 */
typedef struct
{
	struct
	{
		const uint16_t* _remote_rec_task;
		const uint16_t* _state_task;
		const uint16_t* _decision_task;
		const uint16_t* _control_task;
		const uint16_t* _imu_task;
		const uint16_t* _debug_task;
		const uint16_t* _upper_pc_comm_task;
		const uint16_t* _ui_operation_task;
	}TaskFrameCounterPtr;
	struct
	{
		const uint32_t* _remote_rec_task;
		const uint32_t* _state_task;
		const uint32_t* _decision_task;
		const uint32_t* _control_task;
		const uint32_t* _imu_task;
		const uint32_t* _debug_task;
		const uint32_t* _upper_pc_comm_task;	
		const uint32_t* _ui_operation_task;
	}TaskRunPeriodPtr;
}TaskMonitor;
 
/*任务是否卡死标志位或周期扰乱，判断条件根据每个任务的实际监测需求自己写，位掩码如下*/
#define REMOTE_REC_TASK_MASK 0x01
#define STATE_TASK_MASK 	 0x02
#define DECISION_TASK_MASK	 0x04
#define CONTROL_TASK_MASK 	 0x08
#define IMU_TASK_MASK		 0x10
#define DEBUG_TASK_MASK		 0x20
#define UPPER_COMM_TASK_MASK 0x40
#define UI_OPERATION_TASK_MASK 0x80
/*---------------------------------------------------------------------------state task-----------------------------------------------------------------------------------*/
/*define different state*/
/*control terminal*/

#define CONTROL_STOP		0
#define CONTROL_FROM_REMOTE	1
#define CONTROL_FROM_PC		2
#define CONTROL_FROM_REMOTE_CHECK	3


/*chassis mode*/
#define CHASSIS_FOLLOW		0
#define CHASSIS_REVOLVE 	1

/*发射相关*/
#define FRIC_OFF 0
#define FRIC_ON 1
//#define FRIC_READY 2
#define STIR_OFF 0
#define STIR_SPEED_CONTROL 1
#define STIR_ANGLE_CONTROL 2

/*打符*/
#define SHOOT_BUFF_OFF	0
#define SHOOT_BUFF_ON	1
/**
 * @brief 状态机结构体，标识全车变量
 */
typedef  __packed struct
{
	unsigned ctrl_terminal : 2;		//当前控制机器人行为终端：停止控制（保护），遥控器控制，电脑控制
	unsigned chassis_mode : 1;		//底盘当前模式
	unsigned fric_mode : 1;
	unsigned stir_mode : 2;
	unsigned auto_slope : 1;
	
	unsigned power_mode : 1;
	unsigned shoot_buff_mode : 1;
	unsigned auto_aim : 1;
	unsigned force_auto_aim : 1;
	unsigned reserved : 4;
	
	unsigned single_shoot_order_reset :1;
	uint16_t single_shoot_order_cnt;
}RobotState;

void PeripheralRecEnable(void);
#endif
